package gazzera.swing.network;

/* 
 * ColorRenderer.java (compiles with releases 1.2, 1.3, and 1.4) is used by 
 * TableDialogEditDemo.java.
 */

import gazzera.node.core.*;
import gazzera.swing.model.*;
import gazzera.swing.utility.*;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;


public class StatusRenderer extends JLabel
                           implements TableCellRenderer {
    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;
    ImageIcon i = new ImageIcon(ResourceLoader.get("friend_online.png"));
    ImageIcon i2 = new ImageIcon(ResourceLoader.get("friend_offline.png"));
    ImageIcon i3 = new ImageIcon(ResourceLoader.get("stranger.png"));
    
    ImageIcon tron = new ImageIcon(ResourceLoader.get("trusted_online.png"));
    ImageIcon troff = new ImageIcon(ResourceLoader.get("trusted_offline.png"));
    ImageIcon gron = new ImageIcon(ResourceLoader.get("group_online.png"));
    ImageIcon groff = new ImageIcon(ResourceLoader.get("group_offline.png"));

    public StatusRenderer(boolean isBordered) {
        super();
        setHorizontalAlignment(SwingConstants.CENTER);
    	this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.

    }

    public Component getTableCellRendererComponent(
                            JTable table, Object o,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        
    	Connection c = (Connection)o;
    	if(c.status == FriendStatus.STRANGER)
    	{
    		setIcon(i3);
    	}
    	else if(c.status == FriendStatus.FRIEND)
    	{
	    	if (c.onlineStatus == OnlineStatus.ONLINE)
			{
				setIcon(i);
			}
	    	else
	    	{
	    		setIcon(i2);
	    	}
    	}
    	else if(c.status == FriendStatus.TRUSTED)
    	{
	    	if (c.onlineStatus == OnlineStatus.ONLINE)
			{
				setIcon(tron);
			}
	    	else
	    	{
	    		setIcon(troff);
	    	}
    	}
    	else if(c.status == FriendStatus.FOAF)
    	{
	    	if (c.onlineStatus == OnlineStatus.ONLINE)
			{
				setIcon(gron);
			}
	    	else
	    	{
	    		setIcon(groff);
	    	}
    	}
    	if(isSelected)
    	{
    		setBackground(table.getSelectionBackground());
    	}
    	else
    	{
    		setBackground(table.getBackground());
    	}

        return this;
    }
}
